﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace Gemciler_Uretim
{
    public partial class Parametreler : DevExpress.XtraEditors.XtraForm
    {
        public Parametreler()
        {
            InitializeComponent();
        }
        SqlConnecitonClass sqlbaglanti = new SqlConnecitonClass();
         public  Int32 secilen_kod, secilen_kullanici;
         string params_turu = "alis";
        public string user_skin_ismi;
           
            
        private void Parametreler_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = user_skin_ismi;
            DevExpress.Skins.SkinManager.EnableFormSkins();
            this.Text =Convert.ToString("KULLANICI KODU :"+ secilen_kullanici+"");
            kullanıcıGetir();
            dgv_guncelle();
        }
        private void dgv_guncelle()
        {
            string where = "";
            //if (params_turu == "menu") { where = " and params_no>=0 and params_no<1000 "; }
            //if (params_turu == "alis") {where=" and params_no>=1000 and params_no<2000 "; }
            //if (params_turu == "satis") { where = " and params_no>=2000 and params_no<3000 "; }
            //if (params_turu == "siparis") { where = " and params_no>=3000 and params_no<4000 "; }
            //if (params_turu == "sevk") { where = " and params_no>=4000 and params_no<5000 "; }
            //if (params_turu == "kontrol") { where = " and params_no>=5000 and params_no<6000 "; }         
            //if (params_turu == "sayim") { where = " and params_no>=6000 and params_no<7000 "; }

            gridControl1.DataSource = sqlbaglanti.ShowTable("SELECT par_kullanici as KULANICI, params_no AS [PARAMETRE KODU],par_aciklama as [PAREMETRE AÇIKLAMASI] FROM TK_PARAMS WHERE par_kullanici="+secilen_kullanici+" "+where+" ORDER BY params_no ", CommandType.Text);
            this.gridView1.OptionsBehavior.AllowIncrementalSearch = true;
            this.gridView1.OptionsView.ShowAutoFilterRow = true;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridView1.OptionsBehavior.Editable = false;
            gridView1.BestFitColumns();
        
        
        }
        private void kullanıcıGetir()
        {


            gridControl2.DataSource = sqlbaglanti.ShowTable("SELECT [ku_kodu] AS KODU      ,[ku_adi] AS ADI      ,[ku_pw] AS PW "
    +"  FROM [TK_KULLANICI_TANIMLARI]", CommandType.Text);


            //this.gridView1.Columns["TARİH"].DisplayFormat.FormatString = "DD-MM-YYYY SS:dd";

            this.gridControl2.TabIndex = 0;
            this.gridView2.OptionsBehavior.AllowIncrementalSearch = false;
            this.gridView2.OptionsView.ShowAutoFilterRow = false;
            this.gridView2.OptionsView.ShowGroupPanel = false;
            this.gridView2.OptionsBehavior.Editable = false;
            this.gridView2.OptionsBehavior.ReadOnly = false;
            this.gridView2.OptionsView.ColumnAutoWidth = false;
            this.gridView2.OptionsView.HeaderFilterButtonShowMode = FilterButtonShowMode.Button;

             this.gridView2.Columns["PW"].Visible = false;
            this.gridView2.BestFitColumns();

        }
        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {

                int index1 = gridView1.FocusedRowHandle;
                secilen_kod = Convert.ToInt32     (gridView1.GetRowCellValue(index1, "PARAMETRE KODU").ToString());
                string secilen_adi = Convert.ToString(gridView1.GetRowCellValue(index1, "PAREMETRE AÇIKLAMASI").ToString());
                

                ParamsTanimla fr = new ParamsTanimla();
                fr.params_no = secilen_kod;
                fr.kullanici_kodu = secilen_kullanici;
                fr.aciklama = secilen_adi;
                fr.ShowDialog();
                dgv_guncelle();
            }
            catch { }

        }

        private void ekleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParamsTanimla fr = new ParamsTanimla();
            fr.params_no = 0;
            fr.kullanici_kodu = secilen_kullanici;
            fr.ShowDialog();
            dgv_guncelle();
        }

       

        private void sATIŞToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "satis";
            this.Text = "**** SATIŞ PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void sEVKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "sevk"; 
            this.Text = "**** SEVK PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void kONTROLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "kontrol";
            this.Text = "**** KONTROL PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void sAYIMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "sayim";
            this.Text = "**** SAYIM PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void sİPARİŞToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "siparis";
            this.Text = "**** SİPARİŞ PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void mENUToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "menu";
            this.Text = "**** MENU PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void aLIŞToolStripMenuItem_Click(object sender, EventArgs e)
        {
            params_turu = "alis";
            this.Text = "**** ALIŞ PARAMETRELERİ ****";
            dgv_guncelle();
        }

        private void bolumYetkisiAtaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParamsTanimla fr = new ParamsTanimla();
            fr.params_no = 0;
           
            fr.kullanici_kodu = secilen_kullanici;
            fr.params_ekleme_tipi = "bölüm";
            fr.ShowDialog();
            dgv_guncelle();
        }

        private void gridView2_Click(object sender, EventArgs e)
        {
            int index1 = gridView2.FocusedRowHandle;
           
           secilen_kullanici = Convert.ToInt16(gridView2.GetRowCellValue(index1, "KODU").ToString());
            
           dgv_guncelle();
        }

        private void girişEkranAyarlarıToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SISTEM.OtomatikEkranAc fr = new SISTEM.OtomatikEkranAc();
            fr.aktif_kullanici = secilen_kullanici;
            fr.ShowDialog();

        }

        private void textParametreEklemeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParamsTanimla fr = new ParamsTanimla();
            fr.params_no = 0;
            fr.kullanici_kodu = secilen_kullanici;
            fr.params_ekleme_tipi = "par_var";
            fr.ShowDialog();
            dgv_guncelle();
        }

        private void plasiyerYetkisiAtamaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParamsTanimla fr = new ParamsTanimla();
            fr.params_no = 0;
            
            fr.kullanici_kodu = secilen_kullanici;
            fr.params_ekleme_tipi = "personel";
            fr.ShowDialog();
            dgv_guncelle();
        }

       
    }
}